//
//  DDBossInterestingCattleViewController.m
//  DingDongZP
//
//  Created by Jyh on 16/4/27.
//  Copyright © 2016年 iyhjiang.com. All rights reserved.
//

#import "DDBossInterestingCattleViewController.h"
#import "DDDiscoverJobCell.h"
#import "DDJobfindersBaseModel.h"
#import "DDDiscoverJobFinderCell.h"
#import "DDBossInfoService.h"

static NSString *CellReuseIdentifier = @"DDDiscoverJobFinderCell";

@interface DDBossInterestingCattleViewController ()

@property (strong, nonatomic) DDBossInfoService *infoService;

@end

@implementation DDBossInterestingCattleViewController

#pragma mark
#pragma mark - View LifeCycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.title = @"感兴趣的牛人";
    self.view.backgroundColor = [UIColor whiteColor];
    self.infoService = [[DDBossInfoService alloc] init];
    
    [self setupData];
    [self setupView];
}

- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    [self.rdv_tabBarController setTabBarHidden:true animated:true];
}


#pragma mark
#pragma mark - Private Methods

- (void)setupData
{
    self.infoService = [[DDBossInfoService alloc] init];
    
    [self requestAllInterstingCattleInfo];
}

- (void)setupView
{
    [self configureTableView];
}

- (NSMutableArray *)testArray
{

    NSMutableArray *array = [@[] mutableCopy];
    return array;
    
}


- (void)configureTableView
{
    self.tableView.rowHeight = HEIGHT_DISCOVER_CELL;
    self.tableView.tableFooterView = [[UIView alloc] init];
    
//    UINib *cellNib = [UINib nibWithNibName:@"DDDiscoverJobFinderCell" bundle:nil];
//    [self.tableView registerNib:cellNib forCellReuseIdentifier:CellReuseIdentifier];
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.contentInset = UIEdgeInsetsMake(7, 0, 0, 0);
    
    [self addRefreshHeader];
    [self addRefreshFooter];
}

- (void)loadNewData
{
    [self.dataSource removeAllObjects];
    self.startIndexPage = 0;
    [self requestAllInterstingCattleInfo];
}

- (void)loadMoreData
{
    [self requestAllInterstingCattleInfo];
}

- (void)requestAllInterstingCattleInfo
{
    WEAKSELF
    
    [self.infoService queryBossInterestingCattleWithPage:[NSString stringWithFormat:@"%ld",self.startIndexPage] SuccessBlock:^(id responseObject) {

        if ([weakSelf isValidateResponseData:responseObject]) {
            self.startIndexPage ++;
            // 请求数据成功
            DDJobfindersBaseModel *baseModel = [DDJobfindersBaseModel yy_modelWithJSON:responseObject[@"data"]];
            
            [weakSelf setFooterHidden:[baseModel.hasNextPage isEqualToString:@"0"]];
            
            [weakSelf.dataSource addObjectsFromArray:baseModel.jobfinders];
            
            if ([weakSelf.dataSource count] == 0) {
                
                [weakSelf showNoDataViewWithImage:nil text:STR_NODATA];
            } else {
                
                [weakSelf hideNoDataView];
            }
            
            weakSelf.tableView.hidden = self.dataSource.count == 0;
            
            if ([weakSelf isRefreshing]) {
                [weakSelf endRefreshHeader];
                [weakSelf endRefreshFooter];
            }
            
            [weakSelf.tableView reloadData];
            
        } else {
            [weakSelf responseUnValidate:responseObject];
        }
        
    } failBlock:^(id responseObject, NSError *error) {
        [weakSelf requestFaild];
    }];
}


#pragma mark
#pragma mark - CustomDelegate

#pragma mark -
#pragma mark UITableViewDataSource

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.dataSource count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    LDBossRecJobFinderCell *cell = [tableView dequeueReusableCellWithIdentifier:@"jonfinderscell"];
    if (cell == nil) {
        
        cell = [[LDBossRecJobFinderCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"jonfinderscell"];
    }
    
    cell.models = (DDJobfinderDetail *)self.dataSource[indexPath.row];
    return cell;
}

#pragma mark -
#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

//    [tableView deselectRowAtIndexPath:indexPath animated:YES];
//    LDJobfinderDetailBaseVC *vc = [[LDJobfinderDetailBaseVC alloc] init];
//    vc.model = [self.dataSource objectAtIndex:indexPath.row];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
    
    LDJobfinderDetailBaseVCInAll_Show *vc = [[LDJobfinderDetailBaseVCInAll_Show alloc] init];
    
    DDJobfinderDetail *model = [self.dataSource objectAtIndex:indexPath.row];
    vc.userID = model.userid;
    
    [self.navigationController pushViewController:vc animated:YES];
    
}

@end
